package com.zsl.util;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * 宸ュ叿绫�
 * 
 * @author ZSL
 * 
 */
public class Util {
	// 鑾峰彇褰撳墠鏃堕棿
	public String getNowTime() {
		try {
			// SimpleDateFormat dateFormat=new
			// SimpleDateFormat("yyy-MM-DD HH:mm:ss");
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyy-MM-dd");
			String time = dateFormat.format(new Date());
			return time;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			return "";
		}
	}
	//杞崲瀛楃涓�
	public String getJson(List<Map<String, Object>> maps){
		String json="{data:[";
		for (int i = 0; i < maps.size(); i++) {
			Map<String, Object> map=maps.get(i);
			json+="{money:"+map.get("money");
			json+=",people:"+map.get("people");
			json+=",name:"+map.get("name")+"},";
		}
		json=json.substring(0, json.length()-1);
		json+="]}";
		
		return json;
	}
	
	public List<Map<String, Object>> getList(String json){
		try {
			JSONObject jsonObject=new JSONObject(json);
			String data=jsonObject.getString("data");
			JSONArray array=new JSONArray(data);
			List<Map<String, Object>> orderList=new ArrayList<Map<String, Object>>();
			for (int i = 1; i < array.length(); i++) {
				Map<String, Object> map=new HashMap<String, Object>();
				JSONObject orderjson=(JSONObject) array.get(i);
				map.put("name",orderjson.get("name")+"" );
				map.put("people", orderjson.get("people")+"");
				map.put("money",  orderjson.get("money")+"");
				orderList.add(map);
			}
			return orderList;
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
		
	}
	//修改转用
	public List<Map<String, Object>> getUpdateList(String json){
		try {
			JSONObject jsonObject=new JSONObject(json);
			String data=jsonObject.getString("data");
			JSONArray array=new JSONArray(data);
			List<Map<String, Object>> orderList=new ArrayList<Map<String, Object>>();
			for (int i = 0; i < array.length(); i++) {
				Map<String, Object> map=new HashMap<String, Object>();
				JSONObject orderjson=(JSONObject) array.get(i);
				map.put("name",orderjson.get("name")+"" );
				map.put("people", orderjson.get("people")+"");
				map.put("money",  orderjson.get("money")+"");
				orderList.add(map);
			}
			return orderList;
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
		
	}
	
}
